package com.lihao.wanandroid.ui.tree

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lihao.wanandroid.R
import com.lihao.wanandroid.app.util.SettingUtil
import com.lihao.wanandroid.data.model.TreeResponse

class TreeReclassifyAdapter :
    BaseQuickAdapter<TreeResponse.Children, BaseViewHolder>(R.layout.item_public_account) {

    var selectItemPosition: Int = 0

    override fun convert(holder: BaseViewHolder, item: TreeResponse.Children) {
        item.let {
            val tvTitle = holder.getView<TextView>(R.id.tvTitle)
            if (it.isChecked) {
                selectItemPosition = holder.adapterPosition
                tvTitle.setBackgroundResource(R.drawable.bg_orange_radius_20)
                tvTitle.setTextColor(SettingUtil.getColor(context, R.color.white))
            } else {
                tvTitle.setBackgroundResource(R.drawable.bg_white_radius_20)
                tvTitle.setTextColor(SettingUtil.getColor(context, R.color.text_dark))
            }
            holder.setText(R.id.tvTitle, it.name)
        }
    }


    fun selectItem(position: Int) {
        for (publicAcc in data) {
            publicAcc.isChecked = false
        }
        selectItemPosition = position
        data[selectItemPosition].isChecked = true
        notifyDataSetChanged()
    }

}